const path=require('path')
const HTMLWebpackPlugin=require('html-webpack-plugin')
const {CleanWebpackPlugin} =require('clean-webpack-plugin')
const  MiniCssExtractPlugin=require('mini-css-extract-plugin')
const CopyPlugin =require('copy-webpack-plugin')

module.exports={
    devtool:'inline-source-map',

    entry:{
       'js/app':'./src/index.js'
    },
    
    output:{
        path:path.resolve(__dirname,'../dist'),
        // filename:"[name]-[hash:8].js"
    },

performance: {
    hints: "warning", // 枚举
    maxAssetSize: 30000000, // 整数类型（以字节为单位）
    maxEntrypointSize: 50000000, // 整数类型（以字节为单位）
    assetFilter: function(assetFilename) {
    // 提供资源文件名的断言函数
    return assetFilename.endsWith('.css') || assetFilename.endsWith('.js');
    }
    },

    resolve:{
        extensions:['.jsx','.js','mjs','json'],
        alias:{
            '@':path.resolve(__dirname,'../src')
        }
    },

    module:{
        rules:[
            {
                test:/\.m?jsx?$/,
                exclude:/node_modules/,
                use:{
                    loader:'babel-loader',
                    options:{
                        presets:[],
                        plugins:[
                            '@babel/plugin-transform-runtime'
                        ]
                    }
                }
            },
            {
                test:/\.css$/i,
                use:[MiniCssExtractPlugin.loader,'css-loader']
            },
            {
                test:/\.(png|svg|jpg|jpeg|gif)$/i,
                type:'asset/resource',
                // generator:{
                //     filename:'img/[hash][ext][query]'
                // }
            }
        ]
    },


    // devServer:{
    //     contentBase:'./dist',
    //     port:8080,
    //     historyApiFallback:true,
    //     proxy:{
    //         '/api':{
    //             target:'http://localhost:9000',
    //             pathRewrite:{'^/api':''},
    //         }
    //     }
    // },
   
    plugins:[
        new HTMLWebpackPlugin({
            template:'./public/index.html',
            filename:'index.html'
        }),
        // new CleanWebpackPlugin(),
        new MiniCssExtractPlugin({}),
        new CopyPlugin({
            patterns: [
              {
                from: path.resolve(__dirname, '../public'),
                to: path.resolve(__dirname, '../dist'),
                globOptions: {
                  ignore: ["**/index.html", "**/index2.html"],
                },
              }
            ]
          })
    ]
}